package com.xiaodeng.xdblogspringboot.service.impl;

import com.xiaodeng.xdblogspringboot.mapper.CategoryMapper;
import com.xiaodeng.xdblogspringboot.pojo.Category;
import com.xiaodeng.xdblogspringboot.service.CategoryService;
import com.xiaodeng.xdblogspringboot.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    //新增文章类别
    @Override
    public void addcategory(Category category) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer createId = (Integer) map.get("id");
        category.setCreateUser(createId);
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.addcategory(category);
    }
    //  查询文章类别
    @Override
    public List<Category> getCategory() {
        return categoryMapper.getCategory();
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }

    @Override
    public Category update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
        return category;
    }
}
